package cn.francis.chatplatform.modules.session.controller;

import cn.francis.chatplatform.modules.session.bo.CreateSessionBO;
import cn.francis.chatplatform.modules.session.service.ChatSessionService;
import cn.francis.chatplatform.modules.session.vo.request.CreateSessionRequestVO;
import cn.francis.chatplatform.modules.session.vo.response.CreateSessionResponseVO;
import cn.francis.common.annoation.Log;
import cn.francis.common.core.model.AppResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张俊辉
 */

@Slf4j
@RestController
@Tag(name = "创建会话")
@RequiredArgsConstructor
@RequestMapping("create/session")
public class CreateSessionController {

    private final ChatSessionService chatSessionService;

    @Log
    @PostMapping
    public AppResponse<CreateSessionResponseVO> createSession(@RequestBody CreateSessionRequestVO request) {
        log.info("请求参数:{}", request);
        Long id = chatSessionService.save(CreateSessionBO.builder().title(request.getTitle()).build());
        CreateSessionResponseVO createSessionResponseVO = new CreateSessionResponseVO();
        createSessionResponseVO.setSessionId(id);
        return AppResponse.ok(createSessionResponseVO);
    }
}
